package model

import (
	"database/sql"
	"time"

	"github.com/zeromicro/go-zero/core/stores/cache"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

var _ UserModel = (*customUserModel)(nil)

type (
	// UserModel is an interface to be customized, add more methods here,
	// and implement the added methods in customUserModel.
	UserModel interface {
		userModel
	}

	// customUserModel implements UserModel.
	customUserModel struct {
		*defaultUserModel
	}

	// User represents a row from 'users'.
	User struct {
		ID        int64        `db:"id" json:"id"`
		Username  string       `db:"username" json:"username"`
		Email     string       `db:"email" json:"email"`
		Password  string       `db:"password" json:"password"`
		Avatar    sql.NullString `db:"avatar" json:"avatar,omitempty"`
		Status    int64        `db:"status" json:"status"`
		CreatedAt time.Time    `db:"created_at" json:"created_at"`
		UpdatedAt time.Time    `db:"updated_at" json:"updated_at"`
	}
)

// NewUserModel returns a model for the database table.
func NewUserModel(conn sqlx.SqlConn, c cache.CacheConf) UserModel {
	return &customUserModel{
		defaultUserModel: newUserModel(conn, c),
	}
}